package com.prs.crm.action.official;

import java.io.File;
import java.util.Collection;
import java.util.Date;
import java.util.Iterator;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.courser.struts.BaseAction;
import org.courser.ui.PaginationSupport;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

import com.prs.crm.context.AppContext;
import com.prs.crm.context.FileUtil;
import com.prs.crm.context.ToolKits;
import com.prs.crm.domain.Attachment;
import com.prs.crm.domain.archives.ArchivesManager;
import com.prs.crm.domain.archives.ArchivesType;
import com.prs.crm.domain.hr.Person;
import com.prs.crm.domain.official.ShortMenssageCollectType;
import com.prs.crm.domain.official.ShortMessage;
import com.prs.crm.domain.official.ShortMessageCollect;
import com.prs.crm.domain.official.ShortMessageReceive;
import com.prs.crm.service.AttachmentService;
import com.prs.crm.service.archives.ArchivesManagerService;
import com.prs.crm.service.archives.ArchivesTypeService;
import com.prs.crm.service.flow.WorkFlowInstanceService;
import com.prs.crm.service.flow.WorkFlowProcessService;
import com.prs.crm.service.hr.PersonService;
import com.prs.crm.service.official.ShortMenssageCollectTypeService;
import com.prs.crm.service.official.ShortMessageCollectService;
import com.prs.crm.service.official.ShortMessageReceiveService;
import com.prs.crm.service.official.ShortMessageService;

public class ShortMessageAction extends BaseAction{

	private static final long serialVersionUID = 1L;
	private Integer[] ids;
	private PaginationSupport pagination;
	private File upload;
	private String uploadFileName;
	private ShortMessage shortMessage;
	private ShortMessageService shortMessageService;
	private ShortMessageReceive shortMessageReceive;
	private ShortMessageReceiveService shortMessageReceiveService;
	private PersonService personService;
	private String accepts;  //接收人id
	private String type;
	private ShortMessageCollect shortMessageCollect;
	private ShortMessageCollectService shortMessageCollectService;
	private ShortMenssageCollectType shortMenssageCollectType;
	private ShortMenssageCollectTypeService shortMenssageCollectTypeService;
	private Integer id;
	private ArchivesManager archivesManager;
	private ArchivesManagerService archivesManagerService;
	private ArchivesType archivesType;
	private ArchivesTypeService archivesTypeService;
	private Integer[] receiveIds;
	private AttachmentService attachmentService;
	public AttachmentService getAttachmentService() {
		return attachmentService;
	}
	public void setAttachmentService(AttachmentService attachmentService) {
		this.attachmentService = attachmentService;
	}
	public Integer[] getReceiveIds() {
		return receiveIds;
	}
	public void setReceiveIds(Integer[] receiveIds) {
		this.receiveIds = receiveIds;
	}
	public ArchivesManager getArchivesManager() {
		return archivesManager;
	}
	public void setArchivesManager(ArchivesManager archivesManager) {
		this.archivesManager = archivesManager;
	}
	public ArchivesManagerService getArchivesManagerService() {
		return archivesManagerService;
	}
	public void setArchivesManagerService(
			ArchivesManagerService archivesManagerService) {
		this.archivesManagerService = archivesManagerService;
	}
	public ArchivesType getArchivesType() {
		return archivesType;
	}
	public void setArchivesType(ArchivesType archivesType) {
		this.archivesType = archivesType;
	}
	public ArchivesTypeService getArchivesTypeService() {
		return archivesTypeService;
	}
	public void setArchivesTypeService(ArchivesTypeService archivesTypeService) {
		this.archivesTypeService = archivesTypeService;
	}
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public ShortMessageCollect getShortMessageCollect() {
		return shortMessageCollect;
	}
	public void setShortMessageCollect(ShortMessageCollect shortMessageCollect) {
		this.shortMessageCollect = shortMessageCollect;
	}
	public ShortMessageCollectService getShortMessageCollectService() {
		return shortMessageCollectService;
	}
	public void setShortMessageCollectService(
			ShortMessageCollectService shortMessageCollectService) {
		this.shortMessageCollectService = shortMessageCollectService;
	}
	public ShortMenssageCollectType getShortMenssageCollectType() {
		return shortMenssageCollectType;
	}
	public void setShortMenssageCollectType(
			ShortMenssageCollectType shortMenssageCollectType) {
		this.shortMenssageCollectType = shortMenssageCollectType;
	}
	public ShortMenssageCollectTypeService getShortMenssageCollectTypeService() {
		return shortMenssageCollectTypeService;
	}
	public void setShortMenssageCollectTypeService(
			ShortMenssageCollectTypeService shortMenssageCollectTypeService) {
		this.shortMenssageCollectTypeService = shortMenssageCollectTypeService;
	}
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	public PersonService getPersonService() {
		return personService;
	}
	public void setPersonService(PersonService personService) {
		this.personService = personService;
	}
	public String getAccepts() {
		return accepts;
	}
	public void setAccepts(String accepts) {
		this.accepts = accepts;
	}
	public File getUpload() {
		return upload;
	}
	public void setUpload(File upload) {
		this.upload = upload;
	}
	public String getUploadFileName() {
		return uploadFileName;
	}
	public void setUploadFileName(String uploadFileName) {
		this.uploadFileName = uploadFileName;
	}
	public Integer[] getIds() {
		return ids;
	}
	public void setIds(Integer[] ids) {
		this.ids = ids;
	}
	public PaginationSupport getPagination() {
		return pagination;
	}
	public void setPagination(PaginationSupport pagination) {
		this.pagination = pagination;
	}
	public ShortMessage getShortMessage() {
		return shortMessage;
	}
	public void setShortMessage(ShortMessage shortMessage) {
		this.shortMessage = shortMessage;
	}
	public ShortMessageService getShortMessageService() {
		return shortMessageService;
	}
	public void setShortMessageService(ShortMessageService shortMessageService) {
		this.shortMessageService = shortMessageService;
	}
	public ShortMessageReceive getShortMessageReceive() {
		return shortMessageReceive;
	}
	public void setShortMessageReceive(ShortMessageReceive shortMessageReceive) {
		this.shortMessageReceive = shortMessageReceive;
	}
	public ShortMessageReceiveService getShortMessageReceiveService() {
		return shortMessageReceiveService;
	}
	public void setShortMessageReceiveService(
			ShortMessageReceiveService shortMessageReceiveService) {
		this.shortMessageReceiveService = shortMessageReceiveService;
	}
	@Action("editShortMessage")
	public String editShortMessage(){
		if(ids!=null){
			this.shortMessage=this.getShortMessageService().get(ids[0]);
		}
		return SUCCESS;
	}
	@Action("editDraftShortMessage")
	public String editDraftShortMessage(){
		if(ids!=null){
			this.shortMessage=this.getShortMessageService().get(ids[0]);
		}
		return SUCCESS;
	}
	@Action("listSendShortMessage")
	public String listSendShortMessage(){
		DetachedCriteria criteria=this.getPaginationHelper().createQuery(ShortMessage.class);
		criteria.add(Restrictions.eq("oabox", 1)).add(Restrictions.eq("recorder.id",AppContext.getAccountContext().getUser().getId()));
		pagination=this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.getShortMessageService().listByPage(criteria, pagination));
		return SUCCESS;
	}
	@Action("listReceiveShortMessage")
	public String listReceiveShortMessage(){
		DetachedCriteria criteria=this.getPaginationHelper().createQuery(ShortMessageReceive.class);
		criteria.add(Restrictions.eq("oabox", 1)).add(Restrictions.eq("receivePerson.id",AppContext.getAccountContext().getUser().getId()));	
		pagination=this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.getShortMessageReceiveService().listByPage(criteria, pagination));
		return SUCCESS;
	}
	@Action("listDraftShortMessage")
	public String listDraftShortMessage(){
		DetachedCriteria criteria=this.getPaginationHelper().createQuery(ShortMessage.class);
		criteria.add(Restrictions.eq("oabox", 0)).add(Restrictions.eq("recorder.id",AppContext.getAccountContext().getUser().getId()));
		pagination=this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.getShortMessageService().listByPage(criteria, pagination));
		return SUCCESS;
	}
	@Action(value = "sendShortMessage", results = {
			@Result(name = "success", type = "redirect", location = "editShortMessage"),
			@Result(name = "error", type = "chain", location = "editShortMessage") })
	public String sendShortMessage(){
		if (upload!=null) {
			Attachment attach=FileUtil.getInstance().createAttach(upload, uploadFileName);
			this.getAttachmentService().save(attach);
			shortMessage.setAttach(attach);
		}
		shortMessage.setOabox(1);
		shortMessage.setTop(0);
		shortMessage.setCreatTime(new Date());
		shortMessage.setAccepts(accepts);
		this.getShortMessageService().save(shortMessage);
		//已收新闻
		Collection<Person> acceptPerson=this.getPersonService().findPersons(ToolKits.convertStringAryToIntAry(shortMessage.getAccepts().split(",")));
		Iterator<Person> iter=acceptPerson.iterator();
		while (iter.hasNext()) {
			Person person =iter.next();
			ShortMessageReceive re=new ShortMessageReceive();
			re.setShortMessageId(shortMessage.getId());
			re.setTitle(shortMessage.getTitle());
			re.setContent(shortMessage.getContent());
			re.setDegree(shortMessage.getDegree());
			if (shortMessage.getAttach()!=null) {
				re.setAttach(shortMessage.getAttach());
			}
			re.setOabox(1);
			re.setSendPerson(AppContext.getAccountContext().currentUser());
			re.setReceivePerson(person);
			re.setState("未读");
			this.getShortMessageReceiveService().save(re);
		}
		return SUCCESS;
	}
	@Action(value = "sendDraftShortMessage", results = {
			@Result(name = "success", type = "redirect", location = "listDraftShortMessage"),
			@Result(name = "error", type = "chain", location = "listDraftShortMessage") })
	public String sendDraftShortMessage(){
		if (upload!=null) {
			Attachment attach=FileUtil.getInstance().createAttach(upload, uploadFileName);
			this.getAttachmentService().save(attach);
			shortMessage.setAttach(attach);
		}
		shortMessage.setOabox(1);
		shortMessage.setTop(0);
		shortMessage.setCreatTime(new Date());
		shortMessage.setAccepts(accepts);
		this.getShortMessageService().save(shortMessage);
		//已收新闻
		Collection<Person> acceptPerson=this.getPersonService().findPersons(ToolKits.convertStringAryToIntAry(shortMessage.getAccepts().split(",")));
		Iterator<Person> iter=acceptPerson.iterator();
		while (iter.hasNext()) {
			Person person =iter.next();
			ShortMessageReceive re=new ShortMessageReceive();
			re.setShortMessageId(shortMessage.getId());
			re.setTitle(shortMessage.getTitle());
			re.setContent(shortMessage.getContent());
			re.setDegree(shortMessage.getDegree());
			if (shortMessage.getAttach()!=null) {
				re.setAttach(shortMessage.getAttach());
			}
			re.setOabox(1);
			re.setSendPerson(AppContext.getAccountContext().currentUser());
			re.setReceivePerson(person);
			re.setState("未读");
			this.getShortMessageReceiveService().save(re);
		}
		return SUCCESS;
	}
	@Action(value = "sendDraftShortMessages", results = {
			@Result(name = "success", type = "redirect", location = "listDraftShortMessage"),
			@Result(name = "error", type = "chain", location = "listDraftShortMessage") })
	public String sendDraftShortMessages(){
		if (ids!=null) {
			this.shortMessage=this.getShortMessageService().get(ids[0]);
		}
		shortMessage.setOabox(1);
		shortMessage.setTop(0);
		shortMessage.setCreatTime(new Date());
		this.getShortMessageService().submit(shortMessage);
		//已收新闻
		Collection<Person> acceptPerson=this.getPersonService().findPersons(ToolKits.convertStringAryToIntAry(shortMessage.getAccepts().split(",")));
		Iterator<Person> iter=acceptPerson.iterator();
		while (iter.hasNext()) {
			Person person =iter.next();
			ShortMessageReceive re=new ShortMessageReceive();
			re.setShortMessageId(shortMessage.getId());
			re.setTitle(shortMessage.getTitle());
			re.setContent(shortMessage.getContent());
			re.setDegree(shortMessage.getDegree());
			if (shortMessage.getAttach()!=null) {
				re.setAttach(shortMessage.getAttach());
			}
			re.setOabox(1);
			re.setSendPerson(AppContext.getAccountContext().currentUser());
			re.setReceivePerson(person);
			re.setState("未读");
			this.getShortMessageReceiveService().save(re);
		}
		return SUCCESS;
	}
	@Action(value = "saveDraft", results = {
			@Result(name = "success", type = "redirect", location = "editShortMessage"),
			@Result(name = "error", type = "chain", location = "editShortMessage") })
	public String saveDraft(){
		if (shortMessage.getId()==null) {
			shortMessage.setOabox(0);
			shortMessage.setAccepts(accepts);
			this.getShortMessageService().save(shortMessage);
		}else{
			this.getShortMessageService().submit(shortMessage);
		}
		
		return SUCCESS;
	}
	@Action(value = "saveDrafts", results = {
			@Result(name = "success", type = "redirect", location = "listDraftShortMessage"),
			@Result(name = "error", type = "chain", location = "listDraftShortMessage") })
	public String saveDrafts(){
		if (shortMessage.getId()==null) {
			shortMessage.setOabox(0);
			shortMessage.setAccepts(accepts);
			this.getShortMessageService().save(shortMessage);
		}else{
			this.getShortMessageService().submit(shortMessage);
		}
		
		return SUCCESS;
	}
	@Action("viewShortMessageReceive")
	public String viewShortMessageReceive() {
		if(this.ids!=null){
			this.shortMessageReceive=this.getShortMessageReceiveService().get(ids[0]);
		}
		if(shortMessageReceive.getState().equals("未读")){
			shortMessageReceive.setState("已读");
			this.getShortMessageReceiveService().submit(shortMessageReceive);
		}
		return SUCCESS;
	}
	@Action("viewShortMessage")
	public String viewShortMessage() {
		if(ids!=null){
			this.shortMessage=this.getShortMessageService().get(ids[0]);
		}
		return SUCCESS;
	}
	
	@Action("editForwardShortMessage")
	public String editForwardShortMessage(){
		if (shortMessage!=null) {
			shortMessage.setContent("<BR><BR>----- Original Message ----- <BR>"+
				"Form:"+shortMessage.getRecorder().getResume().getName()+"<BR>"+
				"To:"+shortMessage.getReceive()+"<BR>"+
				"Title:"+shortMessage.getTitle()+"<BR>"+
				"Content:"+"<BR>"+
				shortMessage.getContent());
			shortMessage.setTitle("FW:"+shortMessage.getTitle());
		}
		if (shortMessageReceive!=null) {
			shortMessage=new ShortMessage();
			shortMessage.setContent("<BR><BR>----- Original Message ----- <BR>"+
					"Form:"+shortMessageReceive.getRecorder().getResume().getName()+"<BR>"+
					"To:"+shortMessageReceive.getReceivePerson().getResume().getName()+"<BR>"+
					"Title:"+shortMessageReceive.getTitle()+"<BR>"+
					"Content:"+"<BR>"+
					shortMessageReceive.getContent());
			shortMessage.setTitle("FW:"+shortMessageReceive.getTitle());
			if (shortMessageReceive.getAttach()!=null) {
				shortMessage.setAttach(shortMessageReceive.getAttach());
			}
		}
		if (ids!=null) {
			this.shortMessage=this.getShortMessageService().get(ids[0]);
			shortMessage.setContent("<BR><BR>----- Original Message ----- <BR>"+
				"Form:"+shortMessage.getRecorder().getResume().getName()+"<BR>"+
				"To:"+shortMessage.getReceive()+"<BR>"+
				"Title:"+shortMessage.getTitle()+"<BR>"+
				"Content:"+"<BR>"+
				shortMessage.getContent());
			shortMessage.setTitle("FW:"+shortMessage.getTitle());
		}
		if (receiveIds!=null) {
			this.shortMessageReceive=this.getShortMessageReceiveService().get(receiveIds[0]);
			shortMessage=new ShortMessage();
			shortMessage.setContent("<BR><BR>----- Original Message ----- <BR>"+
					"Form:"+shortMessageReceive.getRecorder().getResume().getName()+"<BR>"+
					"To:"+shortMessageReceive.getReceivePerson().getResume().getName()+"<BR>"+
					"Title:"+shortMessageReceive.getTitle()+"<BR>"+
					"Content:<BR>"+shortMessageReceive.getContent());
			shortMessage.setTitle("FW:"+shortMessageReceive.getTitle());
			if (shortMessageReceive.getAttach()!=null) {
				shortMessage.setAttach(shortMessageReceive.getAttach());
			}
		}
		return SUCCESS;
	}
	@Action("editReplyShortMessage")
	public String editReplyShortMessage(){
		if (receiveIds!=null) {
			this.shortMessageReceive=this.getShortMessageReceiveService().get(receiveIds[0]);
//			this.shortMessage=this.shortMessageReceive.getShortMessage();
		}
		ShortMessage sm=this.getShortMessageService().getShortMessageById(shortMessageReceive.getShortMessageId());
		if (sm!=null) {
			if (type.equals("1")) {
				shortMessage=new ShortMessage();
				shortMessage.setContent("<BR><BR>----- Original Message ----- <BR>"+
						"Form:"+sm.getRecorder().getResume().getName()+"<BR>"+
						"To:"+sm.getReceive()+"<BR>"+
						"Title:"+sm.getTitle()+"<BR>"+
						"Content:"+"<BR>"+
						sm.getContent());
					this.accepts=sm.getAccepts();
					shortMessage.setTitle("Fe:"+sm.getTitle());
			}else{
				shortMessage=new ShortMessage();
				String[] receive=sm.getReceive().split(",");
				String[] acc=sm.getAccepts().split(",");
				shortMessage.setContent("<BR><BR>----- Original Message ----- <BR>"+
						"Form:"+sm.getRecorder().getResume().getName()+"<BR>"+
						"To:"+receive[0]+"<BR>"+
						"Title:"+sm.getTitle()+"<BR>"+
						"Content:"+"<BR>"+
						sm.getContent());
				this.accepts=acc[0];
				shortMessage.setTitle("Fe:"+sm.getTitle());
			}
		}
		return SUCCESS;
	}
	@Action(value = "saveSendShortMessageCollect", results = {
			@Result(name = "success", type = "redirect", location = "listSendShortMessage"),
			@Result(name = "error", type = "chain", location = "viewShortMessage?shortMessage=${shortMessage.getId()}") })
	public String saveSendShortMessageCollect(){
		if (shortMessage!=null) {
			shortMessageCollect=new ShortMessageCollect();
			shortMessageCollect.setShortMessage(shortMessage);
			ShortMenssageCollectType sc=this.getShortMenssageCollectTypeService().getShortMenssageCollectType("已发新闻");
			if (sc==null) {
				sc= new ShortMenssageCollectType();
				sc.setName("已发新闻");
				this.getShortMenssageCollectTypeService().save(sc);
			}
			shortMessageCollect.setType(sc);
			this.getShortMessageCollectService().save(shortMessageCollect);
			shortMessage.setOabox(2);//已收藏
			this.getShortMessageService().submit(shortMessage);
		}
		return SUCCESS;
	}
	@Action(value = "saveReceiveShortMessageCollect", results = {
			@Result(name = "success", type = "redirect", location = "listReceiveShortMessage"),
			@Result(name = "error", type = "chain", location = "viewShortMessageReceive?shortMessageReceive=${shortMessageReceive.getId()}") })
	public String saveReceiveShortMessageCollect(){
		if (shortMessageReceive!=null) {
			shortMessageReceive.setOabox(2);//已收藏
			this.getShortMessageReceiveService().submit(shortMessageReceive);
			ShortMessageCollect collect=new ShortMessageCollect();
			collect.setShortMessageReceive(shortMessageReceive);
			ShortMenssageCollectType sc=this.getShortMenssageCollectTypeService().getShortMenssageCollectType("已收新闻");
			if (sc==null) {
				sc=new ShortMenssageCollectType();
				sc.setName("已收新闻");
				this.getShortMenssageCollectTypeService().save(sc);
			}
			collect.setType(sc);
			this.getShortMessageCollectService().save(collect);	
		}
		return SUCCESS;
	}
	@Action("listShortMessageCollect")
	public String listShortMessageCollect(){
		DetachedCriteria criteria=this.getPaginationHelper().createQuery(ShortMessageCollect.class)
		.add(Restrictions.eq("recorder.id",AppContext.getAccountContext().getUser().getId()));
		pagination=this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.getShortMessageCollectService().listByPage(criteria, pagination));
		return SUCCESS;
	}
	@Action("listShortMessageCollectType")
	public String listShortMessageCollectType(){
		DetachedCriteria criteria=this.getPaginationHelper().createQuery(ShortMenssageCollectType.class);
		pagination=this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.getShortMenssageCollectTypeService().listByPage(criteria, pagination));
		return SUCCESS;
	}
	@Action("editShortMessageCollectType")
	public String editShortMessageCollectType(){
		if(ids!=null){
			this.shortMenssageCollectType=this.getShortMenssageCollectTypeService().get(ids[0]);
		}
		return SUCCESS;
	}
	@Action(value = "saveShortMessageCollectType", results = {
			@Result(name = "success", type = "redirect", location = "listShortMessageCollectType"),
			@Result(name = "error", type = "chain", location = "editShortMessageCollectType") })
	public String saveShortMessageCollectType(){
		this.getShortMenssageCollectTypeService().save(shortMenssageCollectType);
		return SUCCESS;
	}
	@Action(value = "removeShortMessageCollectType", results = {
			@Result(name = "success", type = "redirect", location = "listShortMessageCollectType"),
			@Result(name = "error", type = "chain", location = "listShortMessageCollectType") })
	public String removeShortMessageCollectType(){
		if (ids!=null) {
			this.shortMenssageCollectType=this.getShortMenssageCollectTypeService().get(ids[0]);
			if(shortMenssageCollectType.getShortMessageCollects().size()!=0){
				this.addActionError("指定类别为系统内置类别，不能进行操作。");
				return ERROR;
			}
		}
		this.getShortMenssageCollectTypeService().batchRemove(ids);
		return SUCCESS;
	}
	@Action(value = "removeSendShortMessage", results = {
			@Result(name = "success", type = "redirect", location = "listSendShortMessage"),
			@Result(name = "error", type = "chain", location = "listSendShortMessage") })
	public String removeSendShortMessage(){
		if (ids!=null) {
			this.shortMessage=this.getShortMessageService().get(ids[0]);
			if (shortMessage.getShortMessageCollects().size()!=0) {
				this.addActionError("信息已收藏，不能删除！");
				return ERROR;
			}
		}
		this.getShortMessageService().batchRemove(ids);
		return SUCCESS;
	}
	@Action(value = "removeSendShortMessages", results = {
			@Result(name = "success", type = "redirect", location = "listSendShortMessage"),
			@Result(name = "error", type = "chain", location = "viewShortMessage") })
	public String removeSendShortMessages(){
		if (shortMessage.getShortMessageCollects().size()!=0) {
			this.addActionError("信息已收藏，不能删除！");
			return ERROR;
		}
		this.getShortMessageService().remove(shortMessage);
		return SUCCESS;
	}
	@Action(value = "removeReceiveShortMessage", results = {
			@Result(name = "success", type = "redirect", location = "listReceiveShortMessage"),
			@Result(name = "error", type = "chain", location = "listReceiveShortMessage") })
	public String removeReceiveShortMessage(){
		if (ids!=null) {
			this.shortMessageReceive=this.getShortMessageReceiveService().get(ids[0]);
		}
		this.getShortMessageReceiveService().batchRemove(ids);
		return SUCCESS;
	}
	@Action(value = "removeForwardShortMessage", results = {
			@Result(name = "success", type = "redirect", location = "listDraftShortMessage"),
			@Result(name = "error", type = "chain", location = "listDraftShortMessage") })
	public String removeForwardShortMessage(){
		if (ids!=null) {
			this.shortMessage=this.getShortMessageService().get(ids[0]);
		}
		this.getShortMessageService().batchRemove(ids);
		return SUCCESS;
	}
	@Action(value = "removeReceiveShortMessages", results = {
			@Result(name = "success", type = "redirect", location = "listReceiveShortMessage"),
			@Result(name = "error", type = "chain", location = "viewShortMessageReceive") })
	public String removeReceiveShortMessages(){
		this.getShortMessageReceiveService().remove(shortMessageReceive);
		return SUCCESS;
	}
	@Action(value = "removeShortMessageCollect", results = {
			@Result(name = "success", type = "redirect", location = "listShortMessageCollect"),
			@Result(name = "error", type = "chain", location = "listShortMessageCollect") })
	public String removeShortMessageCollect(){
		if (ids!=null) {
			this.shortMessageCollect=this.getShortMessageCollectService().get(ids[0]);
		}
		this.getShortMessageCollectService().batchRemove(ids);
		return SUCCESS;
	}
	
	@Action(value = "saveMessageFile", results = {
			@Result(name = "success", type = "redirect", location = "listSendShortMessage"),
			@Result(name = "error", type = "chain", location = "listSendShortMessage") })
	public String saveMessageFile(){
		if (ids!=null) {
			this.shortMessage=this.getShortMessageService().get(ids[0]);
		}
		this.archivesType=this.archivesTypeService.get(id);
		ArchivesManager am=new ArchivesManager();
		am.setArchivesType(archivesType);
		am.setNumber("MSG"+new Date().getTime()+"G");
		am.setArchivesName(shortMessage.getTitle());
		am.setDegree(shortMessage.getDegree());
		am.setSendTime(shortMessage.getRecordTime());
		am.setSendPerson(shortMessage.getRecorder());
		am.setReceivePerson(shortMessage.getReceive());
		am.setContent(shortMessage.getContent());
		am.setState(0);
		if (shortMessage.getAttach()!=null) {
			am.setAttach(shortMessage.getAttach());
		}
		am.setMark(1);
		this.getArchivesManagerService().save(am);
		shortMessage.setOabox(4);//4为归档
		this.getShortMessageService().submit(shortMessage);
		return SUCCESS;
	}
	@Action(value = "saveMessageReceiveFile", results = {
			@Result(name = "success", type = "redirect", location = "listReceiveShortMessage"),
			@Result(name = "error", type = "chain", location = "listReceiveShortMessage") })
	public String saveMessageReceiveFile(){
		if (ids!=null) {
			this.shortMessageReceive=this.getShortMessageReceiveService().get(ids[0]);
		}
		this.archivesType=this.archivesTypeService.get(id);
		ArchivesManager am=new ArchivesManager();
		am.setArchivesType(archivesType);
		am.setNumber("MSG"+new Date().getTime()+"G");
		am.setArchivesName(shortMessageReceive.getTitle());
		am.setDegree(shortMessageReceive.getDegree());
		am.setSendTime(shortMessageReceive.getRecordTime());
		am.setSendPerson(shortMessageReceive.getRecorder());
		am.setReceivePerson(shortMessageReceive.getReceivePerson().getResume().getName());
		am.setContent(shortMessageReceive.getContent());
		am.setState(0);
		if (shortMessageReceive.getAttach()!=null) {
			am.setAttach(shortMessageReceive.getAttach());
		}
		am.setMark(1);
		this.getArchivesManagerService().save(am);
		shortMessageReceive.setOabox(4);//4为归档
		this.getShortMessageReceiveService().submit(shortMessageReceive);
		return SUCCESS;
	}
	@Action(value = "saveMessageCollectFile", results = {
			@Result(name = "success", type = "redirect", location = "listShortMessageCollect"),
			@Result(name = "error", type = "chain", location = "listShortMessageCollect") })
	public String saveMessageCollectFile(){
		if (ids!=null) {
			this.shortMessageCollect=this.getShortMessageCollectService().get(ids[0]);
		}
		this.archivesType=this.archivesTypeService.get(id);
		ArchivesManager am=new ArchivesManager();
		am.setArchivesType(archivesType);
		am.setNumber("MSG"+new Date().getTime()+"G");
		am.setArchivesName(shortMessageCollect.getShortMessage().getTitle());
		am.setDegree(shortMessageCollect.getShortMessage().getDegree());
		am.setSendTime(shortMessageCollect.getShortMessage().getRecordTime());
		am.setSendPerson(shortMessageCollect.getShortMessage().getRecorder());
		am.setReceivePerson(shortMessageCollect.getShortMessage().getReceive());
		am.setContent(shortMessageCollect.getShortMessage().getContent());
		am.setState(0);
		if (shortMessageCollect.getShortMessage().getAttach()!=null) {
			am.setAttach(shortMessageCollect.getShortMessage().getAttach());
		}
		am.setMark(1);
		this.getArchivesManagerService().save(am);
		shortMessageCollect.getShortMessage().setOabox(4);//4为归档
		this.getShortMessageCollectService().submit(shortMessageCollect);
		return SUCCESS;
	}
}
